<?php
// +----------------------------------------------------------------------
// | 会员一些附加信息
// +----------------------------------------------------------------------

namespace Home\Controller;
use Common\Controller\Base;
use Common\Model\Model;

class MemberController extends Base {

    //单页信息详情
    public function daren(){

        $userModel=M('User');
        $where['status']=array('EQ',true);
        $count = $userModel->where($where)->count();
        $page = $this->Pages($count, 40);
        $pageurl='?page='.urlencode('[PAGE]');
        $page->url     = __APP__.'/member/daren/'.$pageurl;
        $list=$userModel
            ->where($where)
            ->field('userid,uavatar,openuid,nickname,worksnum,spnum,fansnum')
            ->order('worksnum DESC')
            ->limit($page->firstRow . ',' . $page->listRows)
            ->select();
        foreach($list as $key=>$value){
            if(M('UserFans')->where(array('userid'=>$value['userid'],'myid'=>$this->userid,'status'=>true))->count()>0){
                $list[$key]['isfans']=true;
            }
        }
        $this->assign("list", $list);
        $this->assign("Page", $page->show());

        $this->display();
    }

    //焙友动态
    public function dynamic(){
        $userModel=M('UserDynamic');
        $count = $userModel->count();
        $page = $this->Pages($count, 30);
        $pageurl='?page='.urlencode('[PAGE]');
        $page->url     = __APP__.'/member/dynamic/'.$pageurl;
        $unModel=new Model();
        $list=$unModel->table(array(
            C('DB_PREFIX')."user_dynamic"=>'D',
            C('DB_PREFIX')."user"=>'U',
        ))
            ->where('D.userid=U.userid')
            ->field('U.userid,U.uavatar,U.openuid,U.nickname,D.create_time,D.content')
            ->order('D.id DESC')
            ->limit($page->firstRow . ',' . $page->listRows)
            ->select();

        $this->assign("list", $list);
        $this->assign("Page", $page->show());
        $this->assign('navtitle','焙友动态');

        $this->display();
    }


    //排名
    public function rank(){
        $userModel=M('UserDynamic');
        $where['action']='sign';
        $stime=strtotime(date('Y-m-d 00:00:00'));
        $etime=strtotime(date('Y-m-d 23:59:59'));
        $where['create_time']=array(array('GT',$stime),array('LT',$etime),'and');
        $count = $userModel->where($where)->count();
        $page = $this->Pages($count, 30);
        $pageurl='?page='.urlencode('[PAGE]');
        $page->url     = __APP__.'/member/rank/'.$pageurl;
        $unModel=new Model();
        $list=$unModel->table(array(
            C('DB_PREFIX')."user_dynamic"=>'D',
            C('DB_PREFIX')."user"=>'U',
        ))
            ->where('D.userid=U.userid and D.action="sign" and D.create_time>'.$stime.' and D.create_time<'.$etime)
            ->field('U.userid,U.uavatar,U.openuid,U.nickname,D.create_time,D.content')
            ->order('D.create_time DESC')
            ->limit($page->firstRow . ',' . $page->listRows)
            ->select();

        $this->assign("list", $list);
        $this->assign('navtitle','今天签到排名');
        $this->assign("Page", $page->show());

        $this->display('dynamic');
    }



}